#!/usr/bin/env python

import os.path, ConfigParser

try:
    import sqlite3
except:
    from pysqlite2 import dbapi2 as sqlite3

class database:

    PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
    configfile = os.path.join(PROJECT_PATH, "pyews.conf")
    config = ConfigParser.ConfigParser()
    config.read(configfile)
    dbfile = os.path.join(PROJECT_PATH, config.get("database", "dbfile"))
    
    def connect(self):
        try:
            con = sqlite3.connect(self.dbfile)
            con.isolation_level = None
            cur = con.cursor()
            return cur
        except:
            pass
        
    def getMember(self):
        con = self.connect()
        con.execute('select phone_number from member')
        return con
        
    def insert(self, phnumb, name="unknown"):
        con = self.connect()
        con.execute("insert into member(phone_number, name) values('"+ phnumb +"', '"+ name +"')")

    def delete(self, phnumb):
        con = self.connect()
        con.execute("delete from member where phone_number = '"+ phnumb +"'")
